#include"processbar.h"
#include<time.h>
#include<stdlib.h>
#include<unistd.h>

#define FILESIZE 1024*1024*1024

void download(callback_t cb)
{
    srand(time(NULL)^1023);
    int total = FILESIZE;
    while(total)
    {
        usleep(10000);
        int one = rand()%(1024*1024*5);
        total-=one;
        if(total<0) total = 0;
        int download = FILESIZE - total;
        double rate = download * 1.0/(FILESIZE) * 100.0;        //FILESIZE是宏替换要除整体加括号，避免优先级问题
        cb(rate);

    }
}

int main()
{
    download(process_fflush);
    return 0;
}
